ModEditor.Windows.AddObject = {}

function ModEditor.Windows.AddObject.New()
	local obj = ModEditor.GUI.BasicWindow:New()
	obj:Apply({{"Caption","Add Object"},{"X",10},{"Y",10},{"Width",250},{"Height",270},{"ShowFullWindow",true},{"Visible",true}})
	obj.ObjectTypeList = ModEditor.GUI.ListBox:New(obj)
	obj.ObjectTypeList:Apply({{"X",10},{"Y",30},{"Width",obj.Width-20},{"Height",200}})
	obj.ObjectTypeList:Insert({"Box","Sphere","Capsule"})
	obj.OkButton = ModEditor.GUI.Button:New(obj)
	function obj.OkButton:OnClick()
		if self.Parent.ObjectTypeList.SelectedItem ~= 0 then
			local obja = {}
			obja.Type = obj.ObjectTypeList.SelectedItem
			obja.Pos = {0,0,0}
			obja.Color = {1,0,0,0}
			obja.Rot = {0,0,0}
			obja.Size = {1,1,1}
			local id = 0
			local ended = false
			local name
			while not ended do
				id = id + 1
				name = self.Parent.ObjectTypeList.Items[obja.Type][1]..id
				ended = true
				for i = 1,#ModEditor.ObjectList do
					if ModEditor.ObjectList[i].Name == name then
						ended = false
						break
					end
				end
			end
			obja.Name = name
			table.insert(ModEditor.ObjectList,obja)
			ModEditor.Windows.ObjectControl.ObjectList:Insert({obja.Name})
			ModEditor.Windows.Remove(self.Parent.Id)
			ModEditor.Windows.ObjectControl.Child = nil
		end
	end
	obj.OkButton:Apply({{"X",10},{"Y",240},{"Width",22},{"Height",20},{"Caption","Ok"}})
	obj.CancelButton = ModEditor.GUI.Button:New(obj)
	function obj.CancelButton:OnClick()
		ModEditor.Windows.ObjectControl.Child = nil
		ModEditor.Windows.Remove(self.Parent.Id)
	end
	obj.CancelButton:Apply({{"X",42},{"Y",240},{"Width",52},{"Height",20},{"Caption","Cancel"}})
	obj:AddControl(obj.OkButton)
	obj:AddControl(obj.CancelButton)
	obj:AddControl(obj.ObjectTypeList)
	ModEditor.Windows.Add(obj)
	ModEditor.Windows.Activate(obj.Id)
	return obj
end
